home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / MKTONE.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  879b  |  46 lines

  1. /*
  2. **  MKTONE.C
  3. */
  4.  
  5. #include "uclock.h"
  6. #include "sound.h"
  7.  
  8. static int usec_timeout(uclock_t start, uclock_t finish, uclock_t usecs)
  9. {
  10.       if (usecs >= (finish - start))
  11.             return 0;
  12.       else  return 1;
  13. }
  14.  
  15. void dosound(int freq)
  16. {
  17.       unsigned i;
  18.  
  19.       outp(C8253, SETIMER);
  20.       i = (unsigned)freq%256;
  21.       outp(F8253, i);
  22.       i = (unsigned)freq/256;
  23.       outp(F8253, i);
  24. }
  25.  
  26. void mktone(int freq, int update, unsigned delay)
  27. {
  28.       uclock_t start;
  29.  
  30.       if (0 == freq)
  31.       {
  32.             soundoff();
  33.             return;
  34.       }
  35.       dosound(freq);
  36.       if (update != UPDATE)
  37.             soundon();
  38.       if (delay == 0)
  39.             return;
  40.       start = usec_clock();
  41.       while (!usec_timeout(start, usec_clock(), 1000L * (long)delay))
  42.             ;
  43.       if (update == TOGGLE)
  44.             soundoff();
  45. }
  46.